package com.beiyou.controller;

import cn.hutool.core.util.ObjectUtil;
import com.beiyou.dao.VenueDao;
import com.beiyou.model.Venue;
import com.beiyou.model.VenueQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: King-lby
 * @Date Created in 2022-11-30 11:41
 */
@RestController
@RequestMapping("/yunji-api/venue")
public class VenueController {

    @Autowired
    private VenueDao venueDao;

    @PostMapping("/insert")
    public Integer insert(@RequestBody Venue venue){
        //省略校验
        return venueDao.insert(venue);
    }

    @PutMapping("/update")
    public Integer update(@RequestBody Venue venue){
        //省略校验
        return  venueDao.update(venue);
    }

    @GetMapping("/select")
    public PageInfo<Venue>  select(VenueQuery query){

        if(ObjectUtil.isNotEmpty(query.getPageNum()) && ObjectUtil.isNotEmpty(query.getPageSize())){
            PageHelper.startPage(query.getPageNum(), query.getPageSize());
        }

        List<Venue> venues = venueDao.select(query);
        PageInfo<Venue> PageInfo = new PageInfo<Venue>(venues);
        return PageInfo;
    }

    @DeleteMapping("/delete")
    public Integer delete(@RequestParam Integer id){
        //校验合法
        return venueDao.delete(id);
    }
}
